﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ItemTools : MonoBehaviour
{
    private static GameObject instance = null;

    private static CharacterItem[] characterItems = null;
    public static void Create(Inventory inventory, Item item)
    {
        if (instance == null)
        {
            instance = Instantiate(Resources.Load<GameObject>("ItemTools"), GameObject.Find("Canvas").transform);
        }
        if (!instance.activeInHierarchy)
        {
            instance.SetActive(true);
        }

        if (characterItems == null)
        {
            characterItems = GameObject.Find("CharacterItem").GetComponentsInChildren<CharacterItem>();
        }

        instance.transform.Find("Use").GetComponent<Button>().onClick.RemoveAllListeners();
        instance.transform.Find("Use").GetComponent<Button>().onClick.AddListener(() =>
        {

            //装戴
            switch (inventory.type)
            {
                case Type.Weapon:
                    CharacterItem.Get((Weapon)inventory, item);
                    instance.SetActive(false);

                    break;
                case Type.Comsuable:
                    instance.SetActive(false);
                    break;
                case Type.Prop:
                    break;
            }
            
        });
        instance.transform.Find("Lose").GetComponent<Button>().onClick.RemoveAllListeners();
        instance.transform.Find("Lose").GetComponent<Button>().onClick.AddListener(() =>
        {
            item.Destroy();
            instance.SetActive(false);
        });
        instance.transform.Find("Destroy").GetComponent<Button>().onClick.RemoveAllListeners();
        instance.transform.Find("Destroy").GetComponent<Button>().onClick.AddListener(() =>
        {
            item.Destroy();
            instance.SetActive(false);
        });
    }
}
